﻿using System.Linq;
using System.Web.Mvc;
using TrainingManagerSystem.WebUI.Models;

namespace TrainingManagerSystem.WebUI.Controllers
{
    public class CourseController : Controller
    {

      //
        // GET: /Course/

        public ActionResult Index()
        {
            var host = ManagerClientService.Client();
            var courseList = host.PagingAllCourse(20, 1);
            ViewBag.DataCategory = CourseExtensionHelper.GetDataForTreeView(host.CourseCategoryFetchAllName().ToList());
            return View(courseList);
        }

        /// <summary>
        /// List All Course By CourseCategoryId
        /// </summary>
        /// <param name="courseCategoryId"></param>
        /// <returns></returns>
        public ActionResult AllCourseByCategoryId(int courseCategoryId)
        {
            var host = ManagerClientService.Client();
            var courseListAllByCategoryId = host.PagingAllCourseByCategoryId(20, 1, courseCategoryId);

            return View(courseListAllByCategoryId);
        }
        /// <summary>
        /// Search Course By CourseCategoryId, CourseName, CourseYear, StartDate, EndDate
        /// </summary>
        /// <param name="categoryId"></param>
        /// <param name="courseName"></param>
        /// <param name="courseYear"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentpage"></param>
        /// <returns></returns>
        
        //[HttpPost]
        //public JsonResult SearchCourse(int categoryId, string courseName, int? courseYear,string startDate,string endDate,int pageSize,int currentpage)
        //{
        
            
        //    var host = ManagerClientService.Client();

        //    if (string.IsNullOrEmpty(startDate))
        //    {
        //        startDate = null;
        //    }

        //    if (string.IsNullOrEmpty(endDate))
        //    {
        //        endDate = null;
        //    }
        //    var a = host.PagingSearchCourseByCategoryId(pageSize, currentpage, categoryId, courseName, courseYear,startDate, endDate);

        //    return Json(a);
        //}

        
        public JsonResult GetCourseInformationCourseId(int courseId)
        {
            var host = ManagerClientService.Client();
            return Json(host.CourseDetailsByCourseId(courseId));
        }
    }
}
